from zope.interface import implements, Interface

from Products.Five import BrowserView
from Products.CMFCore.utils import getToolByName

from my315ok.fangcan import fangcanMessageFactory as _
from my315ok.fangcan.browser.fangcanview import fangcanView

fmt = '%Y-%m-%d'
from datetime import datetime,timedelta
import time
from time import mktime
class IrenthouseView(Interface):
    """
    renthouse view interface
    """

    def test():
        """ test method"""


class renthouseView(fangcanView):
    """
    renthouse browser view
    """
    implements(IrenthouseView)

    def getHouse_age(self):
        timevalue = self.context.getBuild_year()
        if timevalue == None:
            return 0
        if isinstance(timevalue, basestring):
            return 2       
        
        di = time.strptime(timevalue.strftime(fmt),fmt)
        dt = datetime.fromtimestamp(mktime(di))
        now =   datetime.now()
        out = (now -dt).days
        out = int(out/365)
        return out
        